Ext.define('AmpleHarvest.eventHandler.cWindowEvents',
{
	extend						: 'Ext.AbstractComponent',
	requires						:
	[
		"Ext.window.MessageBox"
	],
	uses							: [
	// 'AmpleHarvest.harvestRequest.window.request.cWindow',
	// 'AmpleHarvest.harvestRequest.window.deactivation.cWindow',
	// 'AmpleHarvest.search.window.cSave_EditQuery',
	// 'AmpleHarvest.util.linkParser',
	// 'AmpleHarvest.GUI.article.navigation.files.cFileInfoWin'
	],
	m_obj_Windows					: null,
	m_obj_MsgBus					: null,
	m_obj_Desktop					: null,
	statics							:
	{
		C_STR_EVENT_ARTICLE_OPEN			: "doarticleopen",
		C_STR_EVENT_APPLICATION_OPEN       	: "doapplicationopen",
		C_STR_EVENT_FILE_OPEN       		: "dofileopen",
		C_STR_EVENT_HR_ADD					: "dohradd",
		C_STR_EVENT_VIEW_PROFILE			: "doviewprofile",
		C_STR_EVENT_HR_DEACTIVATE			: "dohrdeactivate",
		C_STR_EVENT_STAT_LOAD				: "dostatload",
		C_STR_EVENT_OPEN_FILE_INFO			: "doopenfileinfo",
		C_STR_EVENT_OPEN_FLATFILE			: "doopenflatfile",
		C_STR_EVENT_REDIRECT				: "doredirect",
		C_STR_EVENT_DOWNLOAD				: "dodownload",
		C_STR_EVENT_REDIRECT_NEW_WIN		: "doredirectnewwin",
		C_STR_EVENT_SAVED_QUERY_ADD			: "dosavedqueryadd",
		C_STR_EVENT_SAVED_QUERY_CHANGED		: "dosavedquerychanged",
		C_STR_EVENT_SAVED_QUERY_EDIT		: "dosavedqueryedit",
		C_STR_EVENT_SEARCH_QUICK			: "dosearchquick",
		C_STR_EVENT_SEARCH					: "dosearch",
		C_STR_EVENT_ADVANCED_QUERY			: "doadvancedquery",
		C_STR_EVENT_GRAPH_QUERY				: "dographquery",
		C_STR_EVENT_METRICS_SITE_MINE		: "dometricssitemine",
		C_STR_EVENT_METRICS_SITE_DETAIL		: "dometricssitedetail",
		C_STR_EVENT_METRICS_SITE_REPORT		: "dometricssitereport",
		C_STR_EVENT_TOPIC_MODEL				: "dotopicmodel",
		C_STR_EVENT_GE_TPDS_OPEN			: "dogetpdsopen",
		C_STR_EVENT_SEARCH_FACET_FORM		: "docreatefacetform",
		C_STR_EVENT_ADD_ACTION				: "doaddaction",
		C_STR_EVENT_IMPORT_REQUEST			: "doimportrequest",
		C_STR_EVENT_LOAD_IMPORT_REQUEST		: "doloadimportrequest",
		C_STR_EVENT_OPEN_APP2FILE_WINDOW	: "doopenapp2file"
	},

	initComponent					: function()
	{
		this.m_obj_MsgBus.addEvents(
						this.self.C_STR_EVENT_ARTICLE_OPEN,
						this.self.C_STR_EVENT_HR_ADD,
						AmpleHarvest.eventHandler.cWindowEvents.C_STR_EVENT_HR_ADD,
						AmpleHarvest.eventHandler.cWindowEvents.C_STR_EVENT_HR_DEACTIVATE,
						this.self.C_STR_EVENT_VIEW_PROFILE,
						AmpleHarvest.eventHandler.cWindowEvents.C_STR_EVENT_VIEW_PROFILE,
						this.self.C_STR_EVENT_STAT_LOAD,
						this.self.C_STR_EVENT_OPEN_FILE_INFO,
						this.self.C_STR_EVENT_OPEN_FLATFILE,
						this.self.C_STR_EVENT_REDIRECT,
						this.self.C_STR_EVENT_DOWNLOAD,
						this.self.C_STR_EVENT_REDIRECT_NEW_WIN,
						AmpleHarvest.eventHandler.cWindowEvents.C_STR_EVENT_SAVED_QUERY_ADD,
						AmpleHarvest.eventHandler.cWindowEvents.C_STR_EVENT_SAVED_QUERY_CHANGED,
						AmpleHarvest.eventHandler.cWindowEvents.C_STR_EVENT_SAVED_QUERY_EDIT,
						this.self.C_STR_EVENT_SEARCH_QUICK,
						this.self.C_STR_EVENT_SEARCH,
						this.self.C_STR_EVENT_ADVANCED_QUERY,
						this.self.C_STR_EVENT_GRAPH_QUERY,
						this.self.C_STR_EVENT_METRICS_SITE_MINE,
						this.self.C_STR_EVENT_METRICS_SITE_DETAIL,
						this.self.C_STR_EVENT_METRICS_SITE_REPORT,
						this.self.C_STR_EVENT_TOPIC_MODEL,
						this.self.C_STR_EVENT_GE_TPDS_OPEN,
						this.self.C_STR_EVENT_SEARCH_FACET_FORM,
						this.self.C_STR_EVENT_ADD_ACTION,
						this.self.C_STR_EVENT_IMPORT_REQUEST,
						this.self.C_STR_EVENT_LOAD_IMPORT_REQUEST,
						this.self.C_STR_EVENT_FILE_OPEN,
						this.self.C_STR_EVENT_OPEN_APP2FILE_WINDOW
				);

		// Article Events
		this.m_obj_MsgBus.on(this.self.C_STR_EVENT_ARTICLE_OPEN,	this.do_OpenArticle, this );
		this.m_obj_MsgBus.on(this.self.C_STR_EVENT_OPEN_FILE_INFO, this.do_OpenFileInfo, this );
		this.m_obj_MsgBus.on(this.self.C_STR_EVENT_OPEN_FLATFILE, this.do_OpenFlatfile, this );
		
		this.m_obj_MsgBus.addListener(this.self.C_STR_EVENT_APPLICATION_OPEN, this.do_OpenApplication, this );
		this.m_obj_MsgBus.addListener(this.self.C_STR_EVENT_FILE_OPEN, this.do_OpenFile, this );

		// Redirect Events
		this.m_obj_MsgBus.on(this.self.C_STR_EVENT_REDIRECT, this.do_Redirect, this );
		this.m_obj_MsgBus.on(this.self.C_STR_EVENT_DOWNLOAD, this.do_Download, this );

		this.m_obj_MsgBus.on(this.self.C_STR_EVENT_REDIRECT_NEW_WIN, this.do_RedirectNewWin, this );

		// Harvest Request Events
		this.m_obj_MsgBus.on(
						AmpleHarvest.eventHandler.cWindowEvents.C_STR_EVENT_HR_DEACTIVATE,
						this.do_DeactivateHarvestRequestForm, this
				);
		this.m_obj_MsgBus.on(
				AmpleHarvest.eventHandler.cWindowEvents.C_STR_EVENT_HR_ADD,
				this.do_CreateHarvestRequestForm, this
		);
		
		//Import Request Events
		this.m_obj_MsgBus.on(
				AmpleHarvest.eventHandler.cWindowEvents.C_STR_EVENT_IMPORT_REQUEST,
				this.do_CreateImportRequestForm, this
		);
		
		this.m_obj_MsgBus.on(
			AmpleHarvest.eventHandler.cWindowEvents.C_STR_EVENT_LOAD_IMPORT_REQUEST,
			this.do_LoadImportRequestForm, this
		);
		
		this.m_obj_MsgBus.on(
				AmpleHarvest.eventHandler.cWindowEvents.C_STR_EVENT_VIEW_PROFILE,
				this.do_ViewProfile, this
		);

		// Saved Query
		this.m_obj_MsgBus.on(
						AmpleHarvest.eventHandler.cWindowEvents.C_STR_EVENT_SAVED_QUERY_ADD,
						this.do_CreateSavedQueryAddForm, this
				);
		this.m_obj_MsgBus.on(
						AmpleHarvest.eventHandler.cWindowEvents.C_STR_EVENT_SAVED_QUERY_EDIT,
						this.do_CreateSavedQueryEditForm, this
				);
		// Query Events
		this.m_obj_MsgBus.on(this.self.C_STR_EVENT_GRAPH_QUERY,
				this.do_GraphQuery, this
		);

		// Search Quick
		this.m_obj_MsgBus.on(this.self.C_STR_EVENT_SEARCH_QUICK,
				this.do_QuickSearch, this
		);

		// Search
		this.m_obj_MsgBus.on(this.self.C_STR_EVENT_SEARCH,
				this.do_Search, this
		);
		
		// Advanced Query
		this.m_obj_MsgBus.on(this.self.C_STR_EVENT_ADVANCED_QUERY,
				this.do_AdvancedSearch, this
		);
		
		// Site Metrics 
		
		this.m_obj_MsgBus.on(this.self.C_STR_EVENT_METRICS_SITE_MINE,
				this.do_MetricsSiteMine, this
		);
		
		this.m_obj_MsgBus.on(this.self.C_STR_EVENT_METRICS_SITE_DETAIL,
				this.do_MetricsSiteDetail, this
		);
		
		this.m_obj_MsgBus.on(this.self.C_STR_EVENT_METRICS_SITE_REPORT,
				this.do_MetricsSiteReport, this
		);
		
		this.m_obj_MsgBus.on(this.self.C_STR_EVENT_TOPIC_MODEL,
				this.do_TopicModel, this
		);
		
		this.m_obj_MsgBus.on(this.self.C_STR_EVENT_GE_TPDS_OPEN,
				this.do_GETPDSOpen, this
		);
		
		this.m_obj_MsgBus.on(this.self.C_STR_EVENT_SEARCH_FACET_FORM,
				this.do_CreateAddFacetForm, this
		);
		
		this.m_obj_MsgBus.on(this.self.C_STR_EVENT_ADD_ACTION,
				this.do_AddAction, this
		);
		
		// GS specific actions
		this.m_obj_MsgBus.on(this.self.C_STR_EVENT_OPEN_APP2FILE_WINDOW,
				this.do_open_app2file, this
		);
		
		this.callParent();
	},
	
	do_OpenApplication  : function(obj_application)
	{
//		var m_obj_Application = Ext.create('ApplicationDetailView.view.combined.AppView',
		var m_obj_Application = Ext.create('AmpleHarvest.views.application.main', 
	    {
//			appIdLookup : encodeURIComponent(record)
			m_str_id	: obj_application.m_str_id
	    });

//		this.m_obj_MsgBus.fireEvent(AmpleHarvest.eventHandler.cWindowEvents.C_STR_EVENT_ADD_ACTION,
////				'ApplicationDetailView.view.combined.AppView',
//				'AmpleHarvest.views.application.main',
//				'APPLICATION :'+record,
//				{
////					appIdLookup : encodeURIComponent(record)
//					m_str_id	: record
//				}
//			);
      
		this.m_obj_MsgBus.replace_content(m_obj_Application);
	},

	// Article Functions
	do_OpenArticle					: function(str_ID, str_Highlight)
	{
		var arr_Temp = new Array();
		if (typeof str_Highlight == "string")
		{
			str_Highlight = str_Highlight.replace(
					/\*|\(|\)|(\w)*:| AND | OR /gi, " "
			);
			str_Highlight = str_Highlight.replace(/\[(.)* TO (.)*\]/g, "");
			str_Highlight = str_Highlight.replace(/^\s+/g, '');
			str_Highlight = str_Highlight.replace(/\s+$/, '');
			str_Highlight = str_Highlight.replace(/( )* /gi, "_");
			arr_Temp["hl"] = str_Highlight;
		}
		
		var m_obj_Article = Ext.create('AmpleHarvest.views.article.cArticle', 
				{
					m_str_id	: str_ID, //renderTo:"Window"
					json_post 	: arr_Temp
		    	});
		
		this.m_obj_MsgBus.replace_content(m_obj_Article);

	},
	do_OpenFileInfo					: function(str_Title, arr_Data)
	{
		// alert(arr_Data[0].name + " - " + arr_Data[0].value);
		var obj_Window = Ext.create(
				'AmpleHarvest.objects.files.cFileInfoWin',
				{
					title		: str_Title,
					m_arr_Data	: arr_Data
				}
		);
		this.m_obj_Desktop.add(obj_Window);
		obj_Window.show();

		// window.open(AmpleHarvest.util.linkParser.getAddress(str_ID, 1));
	},
	
	do_OpenFlatfile		: function(str_id, str_Highlight)
	{
		//TODO add a str_id validation step
		var obj_params = new Object();
		if(Ext.isObject(str_id))
		{
			obj_params = str_id;
		} else {
			obj_params = {
					m_str_id	: str_id
			}
		}
		console.log(obj_params);
		this.m_obj_MsgBus.m_obj_Layout.fireEvent('doclassificationreset');
		var m_obj_Article = Ext.create('AmpleHarvest.views.flatfile.main', 
				obj_params);
		
		this.m_obj_MsgBus.replace_content(m_obj_Article);
	},

	// Redirect Functions
//	do_Redirect						: function(str_ServerID, str_ID)
//	{
//		location = obj_config.C_STR_EXTERNAL_PATH+'/pages/redirect.php?id='
//				+ str_ID + '&serverId=' + str_ServerID;
//	},
	
	do_Redirect						: function(str_path)
	{
		location = str_path;
	},
	
	do_Download						: function(server_id, str_id)
	{
		location = obj_config.C_ARR_SERVERS[server_id].replace('{id}', str_id);
	},

	do_RedirectNewWin				: function(str_ServerID, str_ID, arr_QueryString)
	{
		var str_Location = obj_config.C_STR_AMPLEHARVEST_BASE_PAGES_PATH+'/redirect.php?id='
				+ str_ID + '&serverId=' + str_ServerID;

		if (arr_QueryString)
		{
			for (var str_Key in arr_QueryString)
			{
				str_Location = str_Location + "&" + str_Key + "="
						+ arr_QueryString[str_Key];
			}
		}

		window.open(str_Location);
	},

	// harvest Request Functions
	do_DeactivateHarvestRequestForm	: function(str_ID)
	{
		var obj_Window = Ext.create('AmpleHarvest.objects.harvestrequest.view.window.deactivation.Window');
		this.m_obj_Desktop.add(obj_Window);
		obj_Window.show();
		obj_Window.set_RequestID(str_ID);
	},

	do_CreateHarvestRequestForm		: function(str_ID, bool_Edit)
	{
		var obj_Window = Ext.create(
				'AmpleHarvest.objects.harvestrequest.view.window.request.Window',
				{
					m_bool_Editable	: bool_Edit
				}
		);
		this.m_obj_Desktop.add(obj_Window);
		obj_Window.show();
		obj_Window.set_RequestID(str_ID);
	},
	
	//Import Request Functions
	do_CreateImportRequestForm	: function(str_ID, bool_Edit)
	{
		this.m_obj_MsgBus.m_obj_Layout.fireEvent('doclassificationreset');
		var m_obj_ImportRequestToolWin = Ext.create('AmpleHarvest.objects.forms.irtCommon', 
			{
				title	: 'New Import Request',
				canEdit	: true,
				canComment : false,
				
				layout	:
				{
					type	: 'vbox',
					align	: 'center'
				}
			}
		);
		this.m_obj_MsgBus.replace_content(m_obj_ImportRequestToolWin);
	},
	
	do_LoadImportRequestForm: function(str_Id, user_Id, bool_Edit, str_winTitle)
	{
		this.m_obj_MsgBus.m_obj_Layout.fireEvent('doclassificationreset');
		var m_obj_ImportRequestToolWin = Ext.create('AmpleHarvest.objects.forms.irtCommon', 
			{
				title	: str_winTitle,
				requestId : str_Id,
				canEdit	: bool_Edit,
				canComment : bool_Edit,
				requestorGUID: user_Id,
				layout	:
				{
					type	: 'vbox',
					align	: 'center'
				}
			}
		);
		
		m_obj_ImportRequestToolWin.getForm().load(
			{
				url: obj_config.C_STR_EXTERNAL_PATH + '/rest/irt/data.php',
				method: 'GET',
				params: {
					id	: str_Id
				},
				
				failure: function(form, action) {
			        Ext.Msg.alert("Load failed", action.result.errorMessage);
			    }
			}
		);
		
		this.m_obj_MsgBus.replace_content(m_obj_ImportRequestToolWin);
	},
	
	
	do_ViewProfile		: function(str_ID)
	{
		var obj_Window = Ext.create(
				'AmpleHarvest.objects.userprofile.view.Window',
				{
					
				}
		);
		this.m_obj_Desktop.add(obj_Window);
		obj_Window.show();
		//obj_Window.set_RequestID(str_ID);
	},
	
	//Add Facet Popup
	do_CreateAddFacetForm		: function(obj_field, str_targetPath)
	{
		var obj_Window = Ext.create(
				'AmpleHarvest.views.facetSelector.main',
				{
					targetPath	: str_targetPath,
					targetField	: obj_field
				}
		);
		this.m_obj_Desktop.add(obj_Window);
		obj_Window.show();

	},

	// Saved Queries
	do_CreateSavedQueryAddForm		: function(str_JSON, obj_config, str_sourceName)
	{
		// alert("Interface - " + str_InterfaceID);
		
//		Ext.encode(
		var obj_Window = Ext.create(
//				'AmpleHarvest.objects.search.window.cSave_EditQuery',
				'AmpleHarvest.views.search.saveQuery',
				{
					title	: "Add Saved Query",
					source	: str_sourceName
				}
		);
		this.m_obj_MsgBus.add(obj_Window);
		obj_Window.show();
		obj_Window.set_QueryString(str_JSON);
		obj_Window.set_Interface(Ext.encode(obj_config));
	},

	do_CreateSavedQueryEditForm		: function(obj_Rec)
	{
		if (!obj_Rec)
		{
			return false;
		}
		var obj_Window = Ext.create(
//				'AmpleHarvest.objects.search.window.cSave_EditQuery',
				'AmpleHarvest.views.search.saveQuery',
				{
					title	: "Add Saved Query"
				}
		);
		this.m_obj_Desktop.add(obj_Window);
		obj_Window.show();
		obj_Window.load_ID(obj_Rec.get("id"));
		// obj_Window.set_QueryString(str_JSON);
		// obj_Window.set_Interface(str_InterfaceID);
	},

	// Search
	do_GraphQuery					: function(str_JsonQuery)
	{
		var obj_Window = Ext.create(
				'AmpleHarvest.search.window.cGraph_Results',
				{
					title			: "Graph Results",
					m_str_JsonQuery	: str_JsonQuery
				}
		);
		this.m_obj_Desktop.add(obj_Window);
		obj_Window.show();
	},

	do_QuickSearch					: function(obj_Data)
	{
		var obj_Param = new Object();
		obj_Param.Query = obj_Data;
		
		
		m_obj_AmpleHarvest_ViewPort
		.fireEvent(
				AmpleHarvest.eventHandler.cMenuEvents.C_STR_EVENT_GO_SEARCH_REAPER,
				{
					json : Ext.encode(obj_Param)
				}
		);
		
//		var obj_Param = new Object();
//		obj_Param.Query = obj_Data;
//
//		var obj_Form = document.createElement("form");
//		obj_Form.setAttribute("method", "post");
//		obj_Form.setAttribute("action",
//				'C_STR_QUICK_SEARCH_PATH'
//		);
//
//		var obj_Field = document.createElement("input");
//		obj_Field.setAttribute("type", "hidden");
//		obj_Field.setAttribute("name", "json");
//		obj_Field.setAttribute("value", Ext.encode(obj_Param));
//
//		obj_Form.appendChild(obj_Field);
//
//		document.body.appendChild(obj_Form);
//		obj_Form.submit();
	},
	
	do_AdvancedSearch				: function(obj_Data)
	{
//		var obj_Param = new Object();
//		obj_Param.Query = obj_Data;
//
//		var obj_Form = document.createElement("form");
//		obj_Form.setAttribute("method", "post");
//		obj_Form.setAttribute("action",
//				'C_STR_ENHANCED_SEARCH_PATH'
//		);
//
//		var obj_Field = document.createElement("input");
//		obj_Field.setAttribute("type", "hidden");
//		obj_Field.setAttribute("name", "json");
//		obj_Field.setAttribute("value", Ext.encode(obj_Param));
//
//		obj_Form.appendChild(obj_Field);
//
//		document.body.appendChild(obj_Form);
//		obj_Form.submit();
//		
		var obj_Param = new Object();
		obj_Param.Query = obj_Data;
		
		m_obj_AmpleHarvest_ViewPort
		.fireEvent(
				AmpleHarvest.eventHandler.cMenuEvents.C_STR_EVENT_GO_SEARCH_BUILDER,
				{
					passedJson : Ext.encode(obj_Param)
				}
		);
	},
	
	do_MetricsSiteMine			: function(str_Path, obj_store)
	{
		obj_store.setProxy(
				{
					type		: 'ajax',
					url			: obj_config.C_STR_EXTERNAL_PATH+'/rest/metrics/cSiteMetrics.php',
					reader		:
					{
						type	: 'json',
						root	: 'data'
					},
					extraParams	: {
						restPath : str_Path
					}
				}
		);
		obj_store.load();
	},
	
	do_MetricsSiteDetail			: function(str_Path)
	{
		var m_obj_View = Ext.create('AmpleHarvest.objects.metrics.site.cDetailReport', 
				{
					m_str_id	: str_Path
		    	});
		
		this.m_obj_MsgBus.replace_content(m_obj_View);
	},
	
	do_MetricsSiteReport			: function(str_Path)
	{
		var m_obj_View = Ext.create('AmpleHarvest.objects.metrics.reports.cReport', 
				{
					m_str_id	: str_Path
		    	});
		
		this.m_obj_MsgBus.replace_content(m_obj_View);
	},
	
	do_TopicModel				: function(str_Path, str_site, str_parent)
	{
		var m_obj_View = Ext.create('AmpleHarvest.views.topicmodel.cDisplayWindow',
				{
					siteURL	 : str_site,
					siteLink : str_Path,
					parentLink : str_parent
				});
		this.m_obj_MsgBus.replace_content(m_obj_View);
	},
	
	do_GETPDSOpen				: function(str_id, str_Highlight)
	{
		var m_obj_View = Ext.create('AmpleHarvest.views.geData.main',
				{
					m_str_id	 	: str_id,
					m_str_highlight	: str_Highlight
				});
		
		this.m_obj_MsgBus.replace_content(m_obj_View);
	},
	
	do_Search			: function(str_path, str_id, obj_searchBox)
	{
		var obj_query = obj_searchBox.get_QueryObject(obj_searchBox.m_obj_search.getForm());
		var str_query = obj_searchBox.build_query(obj_query);
		var obj_results	= obj_searchBox.next('ampleharvest-objects-results-results');
		var obj_search_main = obj_results.ownerCt;

		var params = new Object();
		
		params[obj_searchBox.obj_config.store.terms.query]	= str_query;
		params['wt'] 		= 'json';
		params[obj_searchBox.obj_config.store.proxy.limitParam] = '25';
		
		//TODO : the rows and limit for the time being must be set the same. Find out where the default limit of 25 comes from so they can be changed

		if(Ext.isObject(obj_search_main.obj_config.params))
		{
			for(var key in obj_search_main.obj_config.params)
			{
				params[key] = obj_search_main.obj_config.params[key];
			}
		}
		
		if(Ext.isArray(obj_search_main.obj_config.shards))
		{
			params['shards'] = '';
			var comma = '';
			for(var x in obj_search_main.obj_config.shards)
			{
				if(obj_search_main.obj_config.shards[x] != false)
				{
					params['shards'] += comma+obj_search_main.obj_config.shards[x];
					comma = ',';
				}
			}
		}
		
		obj_results.getStore().set_ExtraParams(params);
		obj_results.getStore().load();

		var obj_tmp = m_obj_AmpleHarvest_ViewPort.down(str_id);

		obj_tmp.obj_config.run = obj_query;
		m_obj_AmpleHarvest_ViewPort.fireEvent(AmpleHarvest.eventHandler.cWindowEvents.C_STR_EVENT_ADD_ACTION,
			str_path,
			obj_searchBox.ownerCt.title+' : <b>'+str_query+'</b>',
			obj_tmp.obj_config
//			{
//				iconCls				: obj_tmp.iconCls,
//				m_DataType			: obj_tmp.m_DataType,
//	    		str_form_path		: obj_tmp.str_form_path,
//	    		str_solr_path		: obj_tmp.str_solr_path,
//	    		str_solr_base		: obj_tmp.str_solr_base,
//	    		str_openAction		: obj_tmp.str_openAction,
//	    		defaultOrient		: obj_tmp.defaultOrient,
//	    		obj_run_search		: obj_tmp.lastQuery
//			}
		);
	},
	
	do_AddAction		: function(str_obj_path, str_title, obj_params)
	{
		var obj_menu = Ext.getCmp('ampleharvest-layout-menu-cmenu-actions').menu;

		obj_menu.insert(0,
				{
		            text  	 : str_title,
//		            tooltip  : "",
		            iconCls  : "menu-search-file-icon",
		            scope		: this,
		            handler  : function()
		            {
		            	console.log(str_obj_path);
		            	console.log(obj_params);
		            	var m_obj_View = Ext.create(str_obj_path,
		            			{
		            				obj_config : obj_params
		            			});
		        		
		        		this.m_obj_MsgBus.replace_content(m_obj_View);
		            }
		         });
		
//		TODO : THIS IS CAUSING A GRAPHICS GLITCH AFTER IT TRIGGERS SEVERAL TIMES
		if(obj_menu.items.length > 25)
		{
			var str_key = obj_menu.items.getAt(obj_menu.items.length - 1).getId();
			obj_menu.items.removeAtKey(str_key);
		}
	},
	
	do_open_app2file	: function(obj_file)//obj_caller, arr_names, arr_data)
	{
		var obj_Window = Ext.create('AmpleHarvest.views.application.appsToFile',
				{
//					ahCaller		: obj_file.ahCaller,
					m_arr_appnames	: obj_file.record.get('Application(s)'),
					m_arr_appdata	: obj_file.record.get('Application Data')
				}
		);
		this.m_obj_MsgBus.add(obj_Window);
		obj_Window.show();
	}
	
}
);